function MysetItem(key, value) {
	if (window.ActiveXObject //ie
	|| (window.MessageEvent && !document.getBoxObjectFor) ) //chrome
	{
		localData.setItem(key,value);
	}
	else if (document.getBoxObjectFor) //firefox
	{
		var pref = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("extensions.axyff.");
		var pls = Components.classes["@mozilla.org/pref-localizedstring;1"].createInstance(Components.interfaces.nsIPrefLocalizedString);
		pls.data = value;
		pref.setComplexValue(key, Components.interfaces.nsIPrefLocalizedString, pls);
		//pref.setCharPref(key, value);
	}
	else alert("no");
}

function GetChormeInnerHTML(nodes) 
{
	var Atitle;
	var Aurl;
    var node = null;
	Atitle=new Array();
	Aurl=new Array();
	for (var i = 0; i < nodes.length; i++) 
    {
        node = nodes[i];
		if(node.tagName=="A")
		{
			if(node.textContent != "" && node.href != "")
			{
			Atitle.push(node.textContent);
			Aurl.push(node.href);
			}
		}
		if(node.childNodes.length>0)
		{
			var aa = node.getElementsByTagName("A");
			for (var j=0;j<aa.length;j++)
			{
				if(aa[j].textContent != "" && aa[j].href != "")
				{

				Atitle.push(aa[j].textContent);
				Aurl.push(aa[j].href);
				}
			}
		}
    }
	MysetItem("Arraytitle", JSON.stringify(Atitle));
	MysetItem("Arrayurl", JSON.stringify(Aurl));
	//alert(JSON.stringify(Atitle));
	//alert(JSON.stringify(Aurl));
	//chrome.extension.sendRequest({msg: "Arraytitle"+JSON.stringify(Atitle)});
	//chrome.extension.sendRequest({msg: "Arrayurl"+JSON.stringify(Aurl)});
}


var axyfirefox = {
	ouraxyff : function() {
	    var isme = content;
 		var vv0 = isme.document.getElementsByName("title");
		if(vv0.length==0) MysetItem("title", isme.document.title); //chrome.extension.sendRequest({msg: "title"+isme.document.title});
		else MysetItem("title", vv0[0].content); //chrome.extension.sendRequest({msg: "title"+vv[0].content});

		var vv = isme.document.getElementsByName("keywords");
		if(vv.length==0) MysetItem("tag", ""); //chrome.extension.sendRequest({msg: "keywords"});
		else MysetItem("tag", vv[0].content); //chrome.extension.sendRequest({msg: "keywords"+vv[0].content});
		
		vv = isme.document.getElementsByName("description");
		if(vv.length==0) MysetItem("intro", ""); //chrome.extension.sendRequest({msg: "description"});
		else  MysetItem("intro", vv[0].content); //chrome.extension.sendRequest({msg: "description"+vv[0].content});

		if(isme.document.location.href) MysetItem("url", isme.document.location.href); //chrome.extension.sendRequest({msg: "url"+isme.document.location.href});
		else MysetItem("url", ""); //chrome.extension.sendRequest({msg: "url"});
		
		var div = isme.document.createElement("div");
		div.setAttribute("onclick", "return window;");
		div.setAttribute("id", "qwertyuas");
		var unsafeWindow = div.onclick();
		if(unsafeWindow.videoId) MysetItem("videoid", unsafeWindow.videoId); //chrome.extension.sendRequest({msg: "videoid"+unsafeWindow.videoId});
		else MysetItem("videoid", ""); //chrome.extension.sendRequest({msg: "videoid"});
		
		isme.openDialog("chrome://axyfirefox/content/web/mainpage.html#tabs-1","", 'width=445,height=444,centerscreen');
		
		
	},
	dosel : function() {
		var isme = content; 
		var sel = isme.getSelection().getRangeAt(0);
		GetChormeInnerHTML(sel.cloneContents().childNodes);
		isme.openDialog("chrome://axyfirefox/content/web/mainpage.html#tabs-2","", 'width=445,height=444,centerscreen');
	}
};	

